package com.domcer.ultra.menu.engine;

import com.domcer.ultra.menu.common.constants.ActionTypeEnum;
import com.domcer.ultra.menu.common.utils.FormatUtil;
import common.utils.MessageUtil;
import common.utils.StringUtils;
import org.bukkit.entity.Player;

import java.util.List;

/**
 * @Author hang.wang
 * @Date 2025/1/31 12:17
 */
public class ActionManager {

    public static void execute(Player player, List<String> actions) {
        actions.forEach(action -> {
            execute(player, action);
        });
    }

    public static void execute(Player player, String action){
        String[] parse = FormatUtil.parse(action);
        if (parse != null) {
            String actionType = parse[0];
            String content = MessageUtil.exchangeMessage(StringUtils.isNotEmpty(parse[1]) ? parse[1] : "", player);
            ActionTypeEnum actionTypeEnum = ActionTypeEnum.getByName(actionType);
            actionTypeEnum.getAction().execute(player, content);
        }
    }
}
